package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.HushenMapper;
import work.xiaohong.gupiao.pojo.Hushen;
import work.xiaohong.gupiao.service.HushenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HushenServiceImpl implements HushenService {

    @Autowired
    private HushenMapper hushenMapper;


    /**
     * 条件+分页查询Hushen
     * @param hushen 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Hushen> findPage(Hushen hushen, int page, int size){
        // 构建查询条件
        QueryWrapper<Hushen> queryWrapper = new QueryWrapper<Hushen>(hushen);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return hushenMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Hushen
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Hushen> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return hushenMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Hushen
     * @param hushen
     * @return
     */
    @Override
    public List<Hushen> findList(Hushen hushen){
        // 构建查询条件
        QueryWrapper<Hushen> queryWrapper = new QueryWrapper<Hushen>(hushen);
        // 查询数据
        return hushenMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Hushen
     * @param id
     */
    @Override
    public void delete(Integer id){
        hushenMapper.deleteById(id);
    }

    /**
     * 根据ID修改Hushen
     * @param hushen
     */
    @Override
    public void update(Hushen hushen){
        hushenMapper.updateById(hushen);
    }

    /**
     * 增加Hushen
     * @param hushen
     */
    @Override
    public void add(Hushen hushen){
        hushenMapper.insert(hushen);
    }

    /**
     * 根据ID查询Hushen
     * @param id
     * @return
     */
    @Override
    public Hushen findById(Integer id){
        return  hushenMapper.selectById(id);
    }

    /**
     * 查询全部Hushen数据
     * @return
     */
    @Override
    public List<Hushen> findAll() {
        return hushenMapper.selectList(null);
    }
}
